package com.itzixi.controller;
/*
@Time     : 2025/3/14 21:04
@Author   : liujingmao
@ClassName: DeepSeekController.java
@Description deepseek对话控制器
*/

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/deepseek")
public class DeepSeekController {

    @Resource
    private ChatClient chatClient;

    //普通对话
    @GetMapping("/ai/v1")
    public Object doChat(@RequestParam(value = "message", defaultValue = "你好") String message) {
        return chatClient.prompt().user(message).call().content();
    }

    //流式对话
    @GetMapping("/ai/stream/v1")
    public Object doChatStream(@RequestParam(value = "message", defaultValue = "你好") String message) {
        Prompt prompt = new Prompt(new UserMessage(message));
        Flux<String> stream = chatClient.prompt(prompt).stream().content();

        List<String> list =  stream.toStream().peek(content->{
        }).collect(Collectors.toList());
        return list;
    }
}
